package com.caseProject.puremvc.mediator.gui
{
	import com.caseProject.puremvc.mediator.gui.simple.SimpleGraphic;
	import com.caseProject.puremvc.model.vo.ElementVO;
	
	import flash.events.MouseEvent;

	public class StateElement extends Element
	{
		private var _simpleGraph:SimpleGraphic;
		private var _enableTransform:Boolean;
		
		public function StateElement()
		{
			super();
			
			this.enableTransform = false;
			this.draw();
		}
		
		public function get enableTransform():Boolean
		{
			return _enableTransform;
		}

		public function set enableTransform(value:Boolean):void
		{
			_enableTransform = value;
		}

		public function get simpleGraph():SimpleGraphic
		{
			return _simpleGraph;
		}

		override public function draw ():void
		{
			super.draw();
			
			var swc:StateSWC = new StateSWC();
			_simpleGraph = new SimpleGraphic(swc);
			this.addChild(simpleGraph);
		}
		
		override public function rename(vo:ElementVO):void
		{
			if (simpleGraph != null)
			{
				simpleGraph.text = "Name: " + vo.name + 
									"\nEntry: " + vo.entry + 
									"\nDoWhile: " + vo.doWhile + 
									"\nExit: " + vo.exit;
			}				
		}
		
		override protected function onMove(event:MouseEvent):void
		{
			super.onMove(event); 
			
			if (this.simpleGraph.mouseX > (this.simpleGraph.width/2) - 50 && 
				this.simpleGraph.mouseY > (this.simpleGraph.height/2) - 50 &&
				this._enableTransform) 
			{	
				this.simpleGraph.redraw(this.simpleGraph.mouseX+5, this.simpleGraph.mouseY+5);
				
				ElementVO(this.vo).heightValue = this.simpleGraph.h;
				ElementVO(this.vo).widthValue = this.simpleGraph.w;
			}
		}
		
		override protected function onUp(event:MouseEvent):void
		{
			super.onUp(event);
			this._enableTransform = false;
		}
		
		override public function redraw(w:Number = 100, h:Number = 50):void
		{
			this.simpleGraph.redraw(w, h);
		}
	}
}